uniform sampler2D textToBlur; // Texture qu'il faut flouter
uniform float textWidth; // La largeur de la texture
uniform float textHeight;// La hauteur de la texture
uniform float blur_kernel; // La taille du noyau de convolution
uniform bool isHorizontal; // Indique si on effectue un flou vertical ou horizontal

void main()
{
	vec2 textSize = vec2(textWidth,textHeight);
	vec2 pas = 1.0/textSize; // Le pas par couleur
	vec2 uv = gl_TexCoord[0].st;
	vec4 color = vec4(0.0, 0.0, 0.0, 1.0);

	
	// Floutage de gauss horizontal
	if(isHorizontal) {
		int j = 0;
		int sum = 0;
		for(float i=-blur_kernel; i<=blur_kernel; i++) {
			vec4 value = texture2D(textToBlur, uv + vec2(pas.x*i, 0.0f));
			int factor = blur_kernel+1.0f - abs(i);
			color += value * factor;
			sum += factor;
		}
		color /= sum;
	}
	
	// Floutage de gauss vertical
	else {
		int j = 0;
		int sum = 0;
		for(float i=-blur_kernel; i<=blur_kernel; i++) {
			vec4 value = texture2D(textToBlur, uv + vec2(0.0f, pas.y*i));
			int factor = blur_kernel+1 - abs(i);
			color += value * factor;
			sum += factor;
		}
		color /= sum;
	}
	
	gl_FragColor = color;
	gl_FragColor.a = 1.0;
}
